<?php

namespace Entity;

class AdminMenu extends \Home {

    private $menu = array(
        'Account' => array(
            'Name' => '账号管理',
            'List' => array(
                'AccountList' => array(
                    'Name' => '账号',
                    'Url' => '/Account/Lists',
                    //'Roles' => [Auth::ACCOUNT_ADD, Auth::ACCOUNT_SHOW],
                ),
            ),
        ),
        'Article' =>array(
            'Name' => '文章管理',
            'List' => array(
                'Category' => array(
                    'Name' => '产品分类管理',
                    'Url' => '/Category/Category',
                ),
                'Add' => array(
                    'Name' => '添加文章',
                    'Url' => '/Article/Add',
                ),
                'Lists' => array(
                    'Name' => '文章列表',
                    'Url' => '/Article/Lists',
                ),
            ),
        ),
        'Message' =>array(
            'Name' => '留言管理',
            'List' => array(
                'Lists' => array(
                    'Name' => '留言列表',
                    'Url' => '/Message/Lists',
                ),
            ),
        ),
        'Company' =>array(
            'Name' => '公司信息',
            'List' => array(
                'Detail' => array(
                    'Name' => '公司详情',
                    'Url' => '/Company/Detail',
                ),
            ),
        ),
        'Advertising' =>array(
            'Name' => '广告信息',
            'List' => array(
                'Add' => array(
                    'Name' => '添加广告',
                    'Url' => '/Advertising/Add',
                ),
                'Lists' => array(
                    'Name' => '广告列表',
                    'Url' => '/Advertising/Lists',
                ),
            ),
        ),
    );

    public function getMenuList() {
        $menu = $this->menu;
        foreach ($menu as  &$val) {
            $val['Roles'] = array();
            foreach ($val['List'] as $v) {
                if (!empty($v['Roles'])) {
                    $roles = is_array($v['Roles']) ? $v['Roles'] : array($v['Roles']);
                    foreach ($roles as $r) {
                        if (!in_array($r, $val['Roles'])) {
                            $val['Roles'][] = $r;
                        }
                    }
                }
            }
        }
        $categories = \Data\Category::instance()->getRootCategories();
        foreach ($categories as $category) {
            $list = array();
            // 多分类
            if ($category['Type'] == 0) {
                $list['Category'] = array(
                    'Name' => '分类管理',
                    'Url' => '/Category/Category?categoryId=' . $category['CategoryId'],
                );
                $list['Article'] = array(
                    'Name' => '文章列表',
                    'Url' => '/Article/Lists?pid=' . $category['CategoryId'],
                );
                $list['AddArticle'] = array(
                    'Name' => '添加文章',
                    'Url' => '/Article/Add?pid=' . $category['CategoryId'],
                );
            } else if ($category['Type'] == 1) {
                $list['Article'] = array(
                    'Name' => '文章列表',
                    'Url' => '/Article/Lists?pid=' . $category['CategoryId'],
                );
                $list['AddArticle'] = array(
                    'Name' => '添加文章',
                    'Url' => '/Article/Add?pid=' . $category['CategoryId'],
                );
            } else if ($category['Type'] == 2) {
                $list['AddArticle'] = array(
                    'Name' => '文章管理',
                    'Url' => '/Article/Goadd?pid=' . $category['CategoryId'],
                );
            }
            $menu['Category_' . $category['CategoryId']] = array(
                'Name' => $category['CategoryName'],
                'List' => $list,
            );
        }
        return $menu;
    }
}